package com.exam.controller;

import com.exam.entity.Question;
import com.exam.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;

@Controller
@RequestMapping("/json")
public class JSONController {

    @Autowired
    QuestionService questionService;

    @GetMapping(value="/test1",produces = {"text/plain;charset=utf-8"})
    @ResponseBody
    public String test1(){
        //会有乱码
        return "hello test1你好";
    }

    @GetMapping("/test2")
    @ResponseBody
    public Object test2(){
        HashMap<String,Object> map = new HashMap<>();
        map.put("code",200);
        map.put("message","添加成功");
        return map;
    }

    @GetMapping("/test3")
    @ResponseBody
    public Object test3(){
        Question question = questionService.getById(1L);
        return question;
    }

    @GetMapping("/test4")
    @ResponseBody
    public Object test4(){
        List<Question> questions = questionService.getByQuery(null);
        return questions;
    }
}
